<!doctype html>
<html>
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    <title>监狱释放-附件信息增加</title>
    <script src="/webjars/miniui/boot.js" type="text/javascript"></script>
    <link href="/static/css/resource.css" rel="stylesheet" type="text/css" />
    <script src="/static/js/common/common.js" type="text/javascript"></script>
    <link href="/webjars/miniui/css/demo.css" rel="stylesheet" type="text/css" />
    <link href="/static/css/default.css" rel="stylesheet" type="text/css" />
    <style>
        .discell {
            text-align:right;
            width:150px;
        }
        .input {
            width:300px;
        }
    </style>
</head>
<body>
<div class="mini-fit" style="margin-bottom: 40px;">
    <form id="form1" method="post" style="height:100%;width: 100%;overflow-x: auto;overflow-y: auto;">
        <!-- 用户 编辑框START-->
        <div id="editform" class="form" style="padding:10px;">
            <input name="id" id="id" class="mini-hidden" style="width: 100%;" readonly />
            <input name="orgName" class="mini-hidden" style="width: 100%;" readonly />
            <input name="priNum" id="priNum" class="mini-hidden" style="width: 100%" readonly />
            <table class="form-table" align="center" style="border-collapse:separate; border-spacing:20px;">

                <tr>
                    <td style="font-weight: bold" class="discell">改造表现附件:</td>
                    <td colspan="3" style="font-size: 12px;font-weight: bold">
                        <input type="button" id="gzbtn" value="上传文件" onclick="onFileUpload('gz')" style="width: 112px" />
                        支持扩展名:.rar .zip .doc .docx .xls .xlsx .pdf .jpg...
                    </td>
                </tr>
                <tr>
                    <td style="font-weight: bold" class="discell">心理健康附件:</td>
                    <td colspan="3" style="font-size: 12px;font-weight: bold">
                        <input type="button" id="xlbtn" value="上传文件" onclick="onFileUpload('xl')" style="width: 112px" />
                        支持扩展名:.rar .zip .doc .docx .xls .xlsx .pdf .jpg...
                    </td>
                </tr>
                <tr>
                    <td style="font-weight: bold" class="discell">是否再犯罪评估附件:</td>
                    <td colspan="3" style="font-size: 12px;font-weight: bold">
                        <input type="button" id="cjbtn" onclick="onFileUpload('cj')" value="上传文件" style="width: 112px" />
                        支持扩展名:.rar .zip .doc .docx .xls .xlsx .pdf .jpg...
                    </td>
                </tr>
                <tr>
                    <td style="font-weight: bold" class="discell"><font color="#dc143c">*</font>刑满释放通知书:</td>
                    <td colspan="3" style="font-size: 12px;font-weight: bold">
                        <input type="button" id="jctzsbtn" onclick="onFileUpload('jctzs')" value="上传文件" style="width: 112px" />
                        支持扩展名:.rar .zip .doc .docx .xls .xlsx .pdf .jpg...
                    </td>
                </tr>
                <tr>
                    <td style="font-weight: bold" class="discell">转入安帮对象通知书:</td>
                    <td colspan="3" style="font-size: 12px;font-weight: bold">
                        <input type="button" id="zrtzsbtn" onclick="onFileUpload('zrtzs')" value="上传文件" style="width: 112px" />
                        支持扩展名:.rar .zip .doc .docx .xls .xlsx .pdf .jpg...
                    </td>
                </tr>
                <tr>
                    <td style="font-weight: bold" class="discell">衔接证据附件:</td>
                    <td colspan="3" style="font-size: 12px;font-weight: bold">
                        <input type="button" id="xjbtn" onclick="onFileUpload('xj')" value="上传文件" style="width: 112px" />
                        支持扩展名:.rar .zip .doc .docx .xls .xlsx .pdf .jpg...
                    </td>
                </tr>
            </table>
        </div>
    </form>
</div>
<script type="text/javascript">
    mini.parse();
    var data1 = []
    var form = new mini.Form("form1");
    var priNum = mini.get("priNum");
    var id = mini.get("id");
    var critype = mini.get("critype");
    var fzlx = mini.get("fzlx");
    var bqzy = mini.get("bqzy");
    var jinengtype = mini.get("jinengtype");
    var pritime = mini.get("pritime");
    var priBegin = mini.get("priBegin");
    var priStop = mini.get("priStop");

    function SetData(data) {
        var pid = priNum.getValue();
        // 根据ID去数据库中查询数据
        $.ajax({
            url: "/azbj/inmates/getseninfo?prinum=" + pid,
            type: "post",
            dataType: "json",
            success: function (sendata) {
                var bf = mini.decode(sendata);
                if (bf != "") {
                    form.setData(bf);
                    form.setChanged(false);
                    critype.setData([{codeId: bf.critype, codeName: bf.critypename}]);
                    mini.get("fzlx").setValue(bf.fzlx);
                    mini.get("fzlx").setText(bf.fzlxname);
                    jinengtype.setData([{codeId: bf.jinengtype, codeName: bf.jinengtypeName}]);
                    pritime.setData([{codeId: bf.pritime, codeName: bf.pritimeName}]);
                    valuechanged();
                }
            }
        });
    }

    function onValidation() {
        var critypeValue = critype.getValue();
        if (critypeValue.length <= 2) {
            critype.setRequired(true);
        }
    }

    function saveData() {
        var critypeValue = critype.getValue();
        if (critypeValue.length <= 2) {
            critype.setRequired(true);
        }
        var addpenaltyId = mini.get("addpenalty").getValue();//拿到选中附加刑的id
        if (addpenaltyId.length > 2) {
            var idsArr = addpenaltyId.split(',');
            for (var i = 0; i < idsArr.length; i++) {
                if ("05" == idsArr[i]) {
                    idsArr.splice(i, 1)
                    delete idsArr[idsArr]
                }
            }
            mini.get("addpenalty").setValue(idsArr.join(','));
        }
        var prival = priNum.getValue();
        form.validate();
        if (form.isValid() == false) {
            return;
        }
        var data = form.getData();
        var json = mini.encode(data);
        if (prival == "") {
            mini.alert("请先保存基本信息");
        } else {
            //校验刑期起日和刑期止日
            if (priBegin.getValue() != "" && priStop.getValue() != "") {
                if (priBegin.getValue() > priStop.getValue()) {
                    mini.alert("刑期起日应该小于刑期止日");
                    return;
                }
            }
            commonSaveData("/azbj/sentence/save", {data: json}, callback);
            // 保存成功的回调函数
            function callback() {
                mini.alert("保存成功");
            }
        }
    }
    }

    window.onload = function () {
        priNum.setValue(${priNum!''});
        if (priNum.getValue() == "") {
            $("#gzbtn").attr("disabled", "disabled");
            $("#xlbtn").attr("disabled", "disabled");
            $("#cjbtn").attr("disabled", "disabled");
            $("#xjbtn").attr("disabled", "disabled");
            $("#jctzsbtn").attr("disabled", "disabled");
            $("#jdbbtn").attr("disabled", "disabled");
            $("#zrtzsbtn").attr("disabled", "disabled");
            $("#qtsjbtn").attr("disabled", "disabled");
            mini.alert("请先保存基本信息");
        } else {
            $("#gzbtn").removeAttr("disabled");
            $("#xlbtn").removeAttr("disabled");
            $("#cjbtn").removeAttr("disabled");
            $("#xjbtn").removeAttr("disabled");
            $("#jctzsbtn").removeAttr("disabled");
            $("#jdbbtn").removeAttr("disabled");
            $("#zrtzsbtn").removeAttr("disabled");
            $("#qtsjbtn").removeAttr("disabled");
        }
    }

    function valuechanged(e) {
        var pritime = mini.get("pritime");
        var pritimeval = pritime.getValue();
        var priStop = mini.get("priStop");
        if (pritimeval == "9997" || pritimeval == "9996" || pritimeval == "9995") {
            priStop.disable();
            priStop.setValue("");
        } else {
            priStop.enable();
        }
    }

    function onFileUpload(e) {
        var idval = id.getValue();
        var prival = priNum.getValue();
        var taskid = "";
        if (e == "gz") {//改造表现附件
            taskid = "4";
        } else if (e == "xl") {//心理健康附件
            taskid = "5";
        } else if (e == "cj") {//出监评估附件
            taskid = "1";
        } else if (e == "xj") {//衔接证据附件
            taskid = "10";
        } else if (e == "jctzs") {//解除社区矫正通知书
            taskid = "33";
        } else if (e == "jdb") {//矫正期限鉴定表
            taskid = "34";
        } else if (e == "zrtzs") {//转入安帮对象通知书
            taskid = "35";
        } else if (e == "qtsj") {//其他社矫附件
            taskid = "36";
        }
        var url = "/upload/user/uploadAppendixfile/view?1=1&id=" + idval + "&priNum=" + prival + "&taskId=" + taskid;
        commonEdit(url, null, null, 600, 400, true, true, true);
    }
</script>
</body>
</html>